#ifndef DBADAPTER_H
#define DBADAPTER_H
#include "dbhelper.h"
#include "QList"
#include "QVariantMap"
#include "dateinteger.h"
#include "bizqueryhelper.h"
#include "toolhelper.h"
#include "QString"
#include <QtCore>
#include <QObject>

class DBAdapter : public QObject
{
    Q_OBJECT
public:
    explicit DBAdapter(QObject *parent = 0);
    explicit DBAdapter(QString dbName,QObject *parent = 0);
    QString _db;
signals:

private:
	QVariantList mapToVariant(QList<QVariantMap> maplist);

public slots:
    //基础
    //true:不需要初始化，或者初始化成功 false:脚本执行有误
    bool InitDb();

    int Insert(QString table,QVariantMap map);
    bool Update(QString table,int fid,QVariantMap map);
    QVariantList Select(QString table,QVariantMap map,QStringList columns,QString filter);
    bool Delete(QString table,QString filter);
    QVariantMap test();

    //获取用户余额
    qreal GetUserAsset();
//    QVariantList GetUserAsset(int UserId);

    //列表查询
//    QList<QVariantMap> GetAllPayment(QDateTime fromDate,QDateTime toDate,int UserId);
    QVariantList GetAllPayment(QDateTime fromDate,QDateTime toDate,int UserId);
    QVariantList GetAllIncome(QDateTime fromDate,QDateTime toDate,int UserId);
    QVariantList GetPaymentType();
    QVariantList GetIncomeType();

    //报表
    //收入类型统计报表
    QVariantList GetIncomeRptGroupByType(QDateTime fromDate,QDateTime toDate,int UserId);
    //支出类型统计报表
    QVariantList GetPaymentRptGroupByType(QDateTime fromDate,QDateTime toDate,int UserId);
    //时间段收入/支出报表
    QVariantList GetIncomeRpt(QDateTime fromDate,QDateTime toDate,int UserId,QString filter = "");
    QVariantList GetPaymentRpt(QDateTime fromDate,QDateTime toDate,int UserId,QString filter = "");
    QVariantList GetdayPaymentRpt(QDateTime d,int UserId,QString filter = "");

    int GetPaymentCount();
    int GetIncomeCount();
    qreal GetPaymentSum();
    qreal GetIncomeSum();
    QDateTime GetLastDate();
};

#endif // DBADAPTER_H
